<template>
<!-- 医院端注册证 -->
  <div class="biz-container">
    <!-- <div style="height:40px;">
        <search-layout
            :formInfos="q_formInfos"
            :formDatas="q_formDatas"
            @onChangeType="onChangeType"
            @onFind="onFind"
        ></search-layout>
    </div> -->
    <batch-operat-btn  
        :addData="false" @onAddData="onAddData"
        :optData="optText" @onOptData="onBatchAudit">>>
        <template #cusBtn>
        </template>
    </batch-operat-btn>
    <a-list-table
        tableId='regisLicenseTable'
        size="small"
        :columns="columns"
        :tableData="listdata"
        :tagClicks="tagClicks"
        :pagination="pagination"
        :isSelecttion="true"
        :loading="loading"
        :scroll="{y:contentH-34}"
        @onTableChange="handleTableChange"
        @onselectChange="onselectChange"
        @onTouchCell="onTouchCell"
        @onAction="onAction"
        @onTouchTagCell="onTouchTagCell"
    >
    </a-list-table>
     <auditModal ref="auditModal" @ok="handleModalSaveOk" @close="handleModalCancel" />
     <licenseImgModal ref="imgModal" :editable="false" />
     <pushRegisLicenseModal ref="pushModal" @close="handlePushModalClosed"/>
     <add-seller-lic-modal ref="addSellerLicModal" @onSaveModal="onSaveModal" /> 
     <add-auth-lic-modal ref="addAuthLicModal" @onSaveModal="onSaveModal" /> 
  </div>
</template>

<script>
import searchLayout from '@/views/app/biz/common/searchLayout'
import batchOperatBtn from '@/views/app/biz/common/batchOperatBtn'
import tableLayout from '@/views/app/biz/common/index'
import aListInfo from '@/views/app/biz/common/aListInfo'
import aListTable from '@/views/app/biz/common/aListTable'
import licenseImgModal from '@/views/app/biz/licenseImg/licenseImgModal'
import auditModal from '@/views/app/biz/regisLicense/auditModal'
import pushRegisLicenseModal from '@/views/app/biz/regisLicense/pushRegisLicenseModal'
import addSellerLicModal from '@/views/app/biz/regisLicense/addSellerLicModal'
import addAuthLicModal from '@/views/app/biz/regisLicense/addAuthLicModal'
import { getByConditions_h, getByConditionsCount_h } from '@/views/app/biz/regisLicense/regisLicense'
import { columns,q_formInfos,q_formDatas} from './regisLicenseConfig'


// 字段列表

const cellTagClicks=['shengChancszzzt','jingXiaosqszt']

export default {
  name:'regisLicense',
  components: {
    searchLayout,
    batchOperatBtn,
    tableLayout,
    aListInfo,
    aListTable,
    auditModal,
    licenseImgModal,
    pushRegisLicenseModal,
    addSellerLicModal,
    addAuthLicModal
  },
  props:{
    contentH:{
        type:Number
    },
    supplierRcd:{
      type:Object
    }
  },
  data() {
    return {
      columns: columns,
      listdata: [],
      tagClicks:cellTagClicks,
      loading: false,
      pagination: {
        //分页配置
        current: 1, //当前页码 current
        pageSize: 10, //每页显示条数 pageSize
        total: 1,
        showQuickJumper: true,
        showSizeChanger: true,
        pageSizeOptions: ['2', '10', '50', '100'],
      },
      // 查询表单
      q_formInfos: q_formInfos,
      // 查询表单绑定数据
      q_formDatas: q_formDatas,
      pData: {}, // 条件查询参数
      optText:'批量审核',
      selectedRowKeys:[],
      selectedRows:[],
      notAudit:false
    }
  },
  watch:{
    supplierRcd(val){
      this.setParams()
    }
  },
  computed: {},
  mounted(){
    this.setParams()
  },
  methods: {
    setParams(){
      console.log('777777777777777777777777777');
      let q_formDatas={...this.q_formDatas}
      q_formDatas.supplierOrgPid= this.supplierRcd?this.supplierRcd.gongYingsOrgPid:null
      q_formDatas.supplierOrgCode= this.supplierRcd?this.supplierRcd.gongYingsdm:null
      this.q_formDatas=q_formDatas
      this.getTotal()
      this.getList(this.q_formDatas)
    },
    // 初始化页面时得到总数
    async getTotal() {
      let pages = ''
      pages = await getByConditionsCount_h(this.q_formDatas)
      console.log(pages)
      if (pages && pages.code && pages.code === 'C1') {
        const pagination = { ...this.pagination }
        pagination.total = pages.data
        this.pagination = pagination
        this.pagination.showTotal =  (showTotal) => {return `共 ${showTotal} 条`}
      }
    },
    // 初始化查询时的数据列表
    async getList(params) {
      console.log('请求列表时传入的数据', params)
      let actionBtn=['证照图片']
      
      this.loading = true
      this.listdata = []
      let res = ''
      res = await getByConditions_h(params, this.pagination)
      this.loading = false
      console.log(res)
      if (res && res.code && res.code === 'C1' && res.data) {
        const resdata = res.data
         for (let item of resdata) {
            switch (item.zhuangTai) {
              case '待审核':
                actionBtn=['审核', '证照图片']
                break;
              default:
                actionBtn=[ '证照图片']
            }
            this.listdata.push({
               key: item.pid,
               action: actionBtn,
               ...item
               }
            )
         }
      } else {
        this.listdata = []
      }
      console.log(this.listdata)
    },
    // 新增按钮 点击了新增
    onAddData() {
      this.$refs.modal.addModal()
    },
    // 关闭模态详细框
    handleModalCancel() {
    },
    // 模态详细框提交按钮
    handleModalSaveOk() {
      this.getList(this.q_formDatas)
    },
    // 标题点击
    onTouchCell (text, record, index) {
      if (index == 'chanPinmc') {
        this.$refs.modal.editModal(record.pid)
      } else if (index == 'shengChancszzzt') {
        this.$refs.imgModal.showModal(record.zhengZhaotpPid)
      }
    },
    handlePushModalClosed () {
      //
    },
    // 操作按钮
    onAction(text, record) {
      if (text == '审核') {
        this.$refs.auditModal.editModal(record.pid,record.zhengZhaotpPid)
      } else if (text == '证照图片') {
        this.$refs.imgModal.showModal(record.zhengZhaotpPid)
      }
    },
    // 触发改变页码,筛选,排序时的回调
    handleTableChange(pagination, filters, sorter) {
      this.pagination.current = pagination.current
      this.pagination.pageSize = pagination.pageSize
      this.getList(this.q_formDatas)
    },
    // 查询按钮
    onFind (){
      this.pagination.current = 1
      this.getTotal()
      this.getList(this.q_formDatas)
    },

    // 查询条件改变时 
    onChangeType (name, val) {
      this.pagination.current = 1
      this.getTotal()
      this.getList(this.q_formDatas)
    },
    // 多选批量操作
    onselectChange(selectedRowKeys,selectedRows ) {
      this.selectedRowKeys=selectedRowKeys
      this.selectedRows=selectedRows
      for (const item of this.selectedRows) {
        if(item.zhuangTai!='待审核'){
          this.notAudit=true
          return
        }else{
          this.notAudit=false
        }
      }
    },
    onBatchAudit(){
      if(this.selectedRows.length){
        if(this.notAudit){
          this.$message.warning({ content:'已选项中含有已审核的记录，请选择待审核的记录', duration: 3 })
        }else{
          this.$refs.auditModal.batchModal(this.selectedRows)
        }
        
      }else{
        this.$message.warning({ content:'未选择要审核的记录', duration: 3 })
      }
    },
    onTouchTagCell(text, record, index,col){
      if(col=='shengChancszzzt'){
        console.log('点击了商家证照的tag:',col);
        //点击了商家证照查看的tag,false表示不可编辑
        this.$refs.addSellerLicModal.editModal(record.pid,false)
      }else if(col=='jingXiaosqszt'){
        console.log('点击了授权书的tag:',col);
        //点击了授权书查看的tag,false表示不可编辑
        this.$refs.addAuthLicModal.editModal(record.pid,false)
      }
    },
    onSaveModal(){
      this.getList(this.q_formDatas)
    }
  },
}
</script>
